package com.ericsson.enap.modules.ossalarm.service.impl;

import com.ericsson.enap.modules.ossalarm.mapper.OssAlarmMapper;
import com.ericsson.enap.modules.ossalarm.mapper.EnipVisExcelModuleDetailMapper;
import com.ericsson.enap.modules.ossalarm.mapper.EnipVisExcelModuleMapper;
import com.ericsson.enap.modules.ossalarm.service.OssFromNMSAlarmService;
import com.ericsson.enap.modules.ossalarm.thread.OssDealAlarmThread;
import com.ericsson.enap.modules.ossalarm.thread.OssReadAlarmThread;
import com.ericsson.enap.modules.sys.entity.EnipNetelement;
import org.slf4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Map;
import java.util.Queue;
import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.stream.Collectors;

@Component
public class OssFromNMSAlarmServiceImpl implements OssFromNMSAlarmService {
    @Autowired
    private OssAlarmMapper ossAlarmMapper;

    @Autowired
    private EnipVisExcelModuleMapper enipVisExcelModuleMapper;

    @Autowired
    private EnipVisExcelModuleDetailMapper visExcelModuleDetailMapper;

    @Value("${TpXmlPathTxtCnAlarm}")
    private String tpXmlPathTxtCnAlarm;
    @Autowired
    private KafkaTemplate<String, String> kafkaTemplate;
    @Override
    public void readAndDealAlarm(List<EnipNetelement> netElements,Logger log) {
        Queue msgQueue=new ConcurrentLinkedQueue();
        Map<String,EnipNetelement> netElementMap=netElements.stream().collect(Collectors.toMap(EnipNetelement::getName,EnipNetelement->EnipNetelement));
        OssReadAlarmThread ossReadAlarmThread=new OssReadAlarmThread(netElementMap,msgQueue,log);
        OssDealAlarmThread ossDealAlarmThread=new OssDealAlarmThread(kafkaTemplate,tpXmlPathTxtCnAlarm, enipVisExcelModuleMapper,visExcelModuleDetailMapper,ossAlarmMapper,netElementMap,msgQueue,log);
        ossReadAlarmThread.start();
        ossDealAlarmThread.start();
    }

    public List<EnipNetelement> queryNetelementList(){
        return ossAlarmMapper.queryEnipNetelementList();
    }
}
